<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div>div</div>
    <p>p</p>
    <div>div</div>
    <span>span</span>
    <p>p</p>
    <div>div</div>
</body>
<script>
    // 根据上次的代码实现链式编程
    function select ( selector ) {
        var obj = document.querySelectorAll( selector );
        obj.each = function ( callback ) {
            each ( obj, callback );
            console.log(this);
        }
        return obj;
    };
    function each ( arr,callback ) {
        for (var i = 0; i < arr.length; i++) {
                callback( i, arr[ i ] );
        }
    };
    select ('div,p').each( function ( i, v ) {
        v.style.border = v.nodeName == 'DIV' ? '1px solid red'
                                             : '1px dashed blue';
    });
    // 还需要解决 each 内部的this 指向问题，以及怎么跳出函数
</script>
</html>